<template>
  <div id="app">
      <div class="header">
          {{ipt}}
          <input type="text" placeholder="搜索" v-model="ipt">
      </div>
      <div class="con">
          <div class="left">
              <ul>
                  <li :class="{'active':i===active}" v-for="(item,i) in list" :key="item.categoryId" @click="change(i)">
                      {{item.name}}
                  </li>
              </ul>
          </div>
          <div class="right">
              <RightView :title="title" :url="url" @search="searchFun"></RightView>
          </div>
      </div>
  </div>
</template>

<script>
import axios from 'axios'
import RightView from './components/RightView'
export default {
  name: 'App',
  created(){
      axios.get('/api/list').then(res => {
          console.log(res);
          if(res.data.code === 1){
              this.list = res.data.data;
              this.title = this.list[0].name;
              this.url = this.list[0].image;
          }
      })
  },
  data(){
      return {
          list:[],
          title:'',
          url:'',
          active:0,
          ipt:''
      }
  },
  components: {
    RightView
  },
  methods:{
      change(i){
          this.active = i;
          this.title = this.list[i].name;
          this.url = this.list[i].image;
      },
      searchFun(url){
          this.ipt = url;
      }
  }
}
</script>

<style lang="scss">
    *{
        margin: 0;
        padding:0;
        list-style: none;
        box-sizing: border-box;
    }
    html,body,#app{
        width:100%;
        height: 100%;
        overflow: hidden;
    }
    #app{
        display: flex;
        flex-direction: column;
        .header{
            width:100%;
            height: 44px;
            background: pink;
        }
        .con{
            width:100%;
            flex:1;
            display: flex;
            .left{
                width:80px;
                height:100%;
                border-right:1px solid gray;
                flex-shrink: 0;
                li{
                    width:100%;
                    height: 44px;
                    border-bottom:1px solid gray;
                    &.active{
                        color:red;
                    }
                }
            }
            .right{
                flex:1;
                height: 100%;
                background: lightblue;
                img{
                    width:100%;
                }
            }
        }
    }
</style>
